package com.itheima.service.impl;

import com.itheima.common.utils.SMSUtils;
import com.itheima.service.SMSService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.time.Duration;

@Service
public class SMSServiceImpl implements SMSService {

    @Autowired
    private RedisTemplate redisTemplate;
    private SMSUtils smsUtils;
    private static final String CAPTCHA_KEY_PREFIX = "captcha:";


    @Override
    public void sendValidateCode(String telephone) {
        String code = (int)((Math.random()*9+1)*1000) + "";
//        smsUtils.sendMessage(SMSUtils.VALIDATE_CODE,telephone, code);
        String  key = CAPTCHA_KEY_PREFIX + telephone;
        redisTemplate.opsForValue().set(key, code, Duration.ofMinutes(5));
    }
}
